package com.dinzeer.slashblade_useful_addon;


import com.dinzeer.slashblade_useful_addon.config.*;
import com.dinzeer.slashblade_useful_addon.data.SuaRecipeGen;
import com.dinzeer.slashblade_useful_addon.events.SpecialMoveHandler;
import com.dinzeer.slashblade_useful_addon.register.LangRegister;
import com.dinzeer.slashblade_useful_addon.register.SUABlock;
import com.dinzeer.slashblade_useful_addon.register.SUACreativeTab;
import com.dinzeer.slashblade_useful_addon.register.SUAItem;
import com.tterrag.registrate.Registrate;
import com.tterrag.registrate.providers.ProviderType;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;

import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Slashblade_useful_addon.MODID)
public class Slashblade_useful_addon {

    // Define mod id in a common place for everything to reference
    public static final String MODID = "slashblade_useful_addon";

    public static final Registrate REGISTRATE = Registrate.create(MODID);



    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(new ResourceLocation(MODID, MODID), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals);
    private static int messageID = 0;

    public static <T> void addNetworkMessage(Class<T> messageType, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, BiConsumer<T, Supplier<NetworkEvent.Context>> messageConsumer) {
        PACKET_HANDLER.registerMessage(messageID, messageType, encoder, decoder, messageConsumer);
        messageID++;
    }

    public Slashblade_useful_addon() {

        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();


        MinecraftForge.EVENT_BUS.register(this);

        REGISTRATE.addDataGenerator(ProviderType.RECIPE, SuaRecipeGen::onRecipeGen);
        SpecialMoveHandler.getInstance().register();
        SUACreativeTab.REGISTRY.register(modEventBus);
        SUAItem.register();
        LangRegister.register();
        SUABlock.register();
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC,"legendrelics/"+MODID+"/"+MODID+"-routine.toml");
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ProudSoulConfig.SPEC,"legendrelics/"+MODID+"/"+MODID+"-proudsoul.toml");
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, KillCountConfig.SPEC,"legendrelics/"+MODID+"/"+MODID+"-killcount.toml");
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, RankConfig.SPEC,"legendrelics/"+MODID+"/"+MODID+"-rank.toml");
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SoulCrystalConfig.SPEC,"legendrelics/"+MODID+"/"+MODID+"-soul_crystal.toml");
    }

    public static ResourceLocation prefix(String path) {

        return new ResourceLocation(MODID, path);
    }
}
